<template>
	<view>
		<uni-popup type="bottom" ref="keyBoardPopup" :maskClick="false">
			<view class="input_pwd-wrap">
				<view class="input-wrap">
					<view class="tit">请输入支付密码
						<uni-icons @click="hide" class="close-icon" type="closeempty" size="30" color="#666"></uni-icons>
					</view>
					<view class="pwd_list-wrap">
						<view class="pwd_list-bg">
							<view 
								class="pwd_item"
								v-for="(item, index) in 6"
								:key="index"
							></view>
						</view>
						<view class="pwd_list">
							<view 
								class="pwd_item pwd"
								v-for="(item, index) in pwdList"
								:key="index"
							></view>
						</view>
					</view>
					<view class="forget_pwd" @click="handleGoEditPayPwd">忘记密码？</view>
				</view>
				
				<view class="key_list">
					<view 
						class="key_item"
						v-for="(it_k, in_k) in keysList"
						:key="in_k"
						@click="handleInputPwd(it_k)"
					>
						{{it_k}}
					</view>
					<view class="key_item" @click="handleInputPwd(-1)">
						<image class="del-icon" src="../../static/imgs/icons/del-icon.png"></image>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pwdList: [],
				flag: true,
				keysList: [1,2,3,4,5,6,7,8,9,'',0],
			}
		},
		
		watch: {
			pwdList() {
				if (this.pwdList.length >= 6) {
					this.$emit('pay', this.pwdList.join(''))
					this.pwdList = []
					this.flag = false
					setTimeout(() => {
						this.flag = true
					},300)
				}
			}
		},
		
		methods: {
			show() {
				this.$refs.keyBoardPopup.open()
			},
			hide() {
				this.$refs.keyBoardPopup.close()
				// this.$emit('cancle')
				this.$emit('closeK')
				this.$store.commit('delOrderPayType')
				this.pwdList = []
			},
			finishHide(){
				this.$store.commit('delOrderPayType')
				this.pwdList = []
			},
			handleInputPwd(num) {
				if (num === '' || !this.flag) return false
				if (num == -1) {
					return this.pwdList = this.pwdList.slice(0, this.pwdList.length-1)
				}
				if (this.pwdList.length < 6) this.pwdList.push(num)
			},
			handleGoEditPayPwd() {
				uni.navigateTo({
					url: '../../pagesUser/editPayPwd?type=2'
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.input_pwd-wrap {
	.input-wrap {
		width: 690rpx;
		margin: 0 auto 123rpx;
		background-color: #fff;
		border-radius: 12rpx;
		.tit {
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			font-size: 32rpx;
			color: #333;
			border-bottom: 1px solid #ebebeb;
			position: relative;
			.close-icon {
				position: absolute;
				top: 50%;
				transform: translateY(-50%);
				left: 12rpx
			}
		}
		.pwd_list-wrap {
			position: relative;
			margin:  60rpx 20rpx 0;
			height: 80rpx;
			z-index: 1;
			.pwd_list-bg {
				display: flex;
				justify-content: space-between;
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				.pwd_item {
					height: 80rpx;
					display: flex;
					flex: 1;
					align-items: center;
					justify-content: space-evenly;
					border: 1px solid #CCCCCC;
					border-right: 1px solid transparent;
					&:last-child {
						border-right: 1px solid #CCCCCC;
					}
				}
			}
			.pwd_list {
				display: flex;
				justify-content: flex-start;
				float: left;
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				z-index: 2;
				.pwd_item {
					height: 80rpx;
					width: 108.3rpx;
					display: flex;
					align-items: center;
					justify-content: space-evenly;
					&.pwd {
						position: relative;
						&::before {
							content: '';
							width: 20rpx;
							height: 20rpx;
							background-color: #333;
							border-radius: 50%;
							position: absolute;
							top: 50%;
							left: 50%;
							transform: translate(-50%, -50%);
						}
					}
				}
			}
		}
		.forget_pwd {
			padding: 0 12rpx;
			height: 80rpx;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			font-size: 24rpx;
			color: #999;
		}
	}
	.key_list {
		display: flex;
		justify-content: space-evenly;
		flex-wrap: wrap;
		background-color: #fff;
		.key_item {
			width: 33%;
			height: 106rpx;
			display: flex;
			align-items: center;
			justify-content: space-evenly;
			font-size: 56rpx;
			color: #030303;
			border: 1px solid #ccc;
			border-right: none;
			border-bottom: none;
			&:nth-child(10) {
				background-color: #e5e8ef;
			}
			&:nth-child(12) {
				background-color: #e5e8ef;
			}
			.del-icon {
				width: 46rpx;
				height: 34rpx;
			}
		}
	}
}
</style>
